home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performSnapKeyArgList.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  11.4 KB  |  382 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Nov 3 98
  22. //
  23. //  Description:
  24. //    This is a helper script to perfrom the snapKey command
  25. //    using the various options that have been set
  26. //
  27. //  Input Arguments:
  28. //        int action        0 - just execute the command
  29. //                        1 - show the option box dialog
  30. //                        2 - return the drag command
  31. //
  32. //  Return Value:
  33. //      None.
  34. //
  35.  
  36. proc setOptionVars (int $forceFactorySettings)
  37. {
  38.     keySetOptionBoxCommon( { "snapKey", 
  39.                              "unknown",
  40.                              "setOptionVars", 
  41.                              $forceFactorySettings,
  42.                              1 } );
  43.     // snapKey time or value?
  44.     //
  45.     if ($forceFactorySettings || !`optionVar -exists snapKeyTimeValue`) {
  46.         optionVar -intValue snapKeyTimeValue 1;
  47.     }
  48.  
  49.     // snapKey time multiple
  50.     //
  51.     if ($forceFactorySettings || !`optionVar -exists snapKeyTimeMultiple`) {
  52.         optionVar -floatValue snapKeyTimeMultiple 1.0;
  53.     }
  54.  
  55.     // snapKey value multiple
  56.     //
  57.     if ($forceFactorySettings || !`optionVar -exists snapKeyValueMultiple`) {
  58.         optionVar -floatValue snapKeyValueMultiple 1.0;
  59.     }
  60. }
  61.  
  62. global proc snapKeySetup (string $parent, string $selectionConnection, int $forceFactorySettings)
  63. {
  64.     // Retrieve the option settings
  65.     //
  66.     setOptionVars ($forceFactorySettings);
  67.  
  68.     setParent $parent;
  69.  
  70.     keySetOptionBoxCommon( { "snapKey", $selectionConnection, "setup", 1 } );
  71.  
  72.     // snap key time or value?
  73.     //
  74.     int $snapTimeValue = `optionVar -query snapKeyTimeValue`;
  75.     radioButtonGrp -edit -select $snapTimeValue snapTimeValue;
  76.  
  77.     // snap time multiple
  78.     //
  79.     float $snapToTime = `optionVar -query snapKeyTimeMultiple`;
  80.     floatFieldGrp -edit -value1 $snapToTime snapToTime;
  81.  
  82.     // snap value multiple
  83.     //
  84.     float $snapToValue = `optionVar -query snapKeyValueMultiple`;
  85.     floatFieldGrp -edit -value1 $snapToValue snapToValue;
  86.  
  87.     // Now get all the dependent widgets in the right 
  88.     // enabled/disabled/collapsed/expanded state
  89.     //
  90.     snapKeyWidgetsEnable ($selectionConnection);
  91. }
  92.  
  93. global proc snapKeyCallback( string $parent, int $doIt,
  94.                              string $selectionConnection, 
  95.                              int $performAction, int $fromGraphEditor )
  96. {
  97.     setParent $parent;
  98.  
  99.     keySetOptionBoxCommon( { "snapKey", $selectionConnection, "callback" } );
  100.  
  101.     // snap time or value?
  102.     //
  103.     optionVar -intValue snapKeyTimeValue `radioButtonGrp -q -sl snapTimeValue`;
  104.  
  105.     // time multiple
  106.     //
  107.     optionVar -floatValue snapKeyTimeMultiple 
  108.         `floatFieldGrp -q -value1 snapToTime`;
  109.  
  110.     // value multiple
  111.     //
  112.     optionVar -floatValue snapKeyValueMultiple 
  113.         `floatFieldGrp -q -value1 snapToValue`;
  114.  
  115.     if( $doIt ) {
  116.         performSnapKeyArgList( 1, { (string) $performAction, 
  117.                                     $selectionConnection, $fromGraphEditor } );
  118.         string $tmpCmd = "performSnapKeyArgList 1 {";
  119.         $tmpCmd += "\"" + $performAction + "\", ";
  120.         $tmpCmd += "\"" + $selectionConnection + "\", ";
  121.         $tmpCmd += "\"" + $fromGraphEditor + "\"}";
  122.         addToRecentCommandQueue $tmpCmd "Snap Keys";
  123.     }
  124. }
  125.  
  126. global proc snapKeyDoSelectionChanged (string $selectionConnection)
  127. //
  128. // Description:
  129. //    Since timeRange is irrelevant when there are 
  130. //    picked keyframes, collapse the timeRange
  131. //    when there are.  (This is hooked in to a SelectionChanged
  132. //    trigger.)
  133. //    
  134. {
  135.     keySetOptionBoxCommon( { "snapKey", $selectionConnection, "selectionChanged" } );
  136. }
  137.  
  138.  
  139. global proc snapKeyWidgetsEnable (string $selectionConnection)
  140. //
  141. // Description:
  142. //    These are the widgets that get enabled and
  143. //    disabled based on the certain states.  Put them
  144. //    here so they're all in one place.
  145. //    
  146. {
  147.     keySetOptionBoxCommon( { "snapKey", $selectionConnection, "enable" } );    
  148.  
  149.     // Time/Value multiple fields
  150.     //
  151.     $doTimeValue = `radioButtonGrp -q -select snapTimeValue`;
  152.     floatFieldGrp -e -enable ( $doTimeValue != 2 ) snapToTime;
  153.     floatFieldGrp -e -enable ( $doTimeValue != 1 ) snapToValue;
  154. }
  155.  
  156. proc string snapKeyWidgets( string $tabLayout, string $selectionConnection, int $fromGraphEditor )
  157. {
  158.     global int $gTextColumnWidthIndex;
  159.  
  160.     setParent $tabLayout;
  161.  
  162.     string $tabForm = `columnLayout -adjustableColumn true`;
  163.  
  164.     keySetOptionBoxCommon( { "snapKey", $selectionConnection, "widgets", $fromGraphEditor, 1 } );
  165.  
  166.     radioButtonGrp -nrb 3 -label "Snap" 
  167.         -label1 "Times"
  168.         -label2 "Values"
  169.         -label3 "Both"
  170.         -sl 1
  171.         -changeCommand ("snapKeyWidgetsEnable " + $selectionConnection)
  172.         snapTimeValue;
  173.  
  174.     floatFieldGrp -label "Snap Times to Multiple of" -value1 1.0 snapToTime;
  175.     floatFieldGrp -label "Snap Values to Multiple of" -value1 1.0 snapToValue;
  176.  
  177.     setParent ..;
  178.  
  179.     return $tabForm;
  180. }
  181.  
  182. proc snapKeyOptions( string $selectionConnection, int $performAction, 
  183.                      int $fromGraphEditor )
  184. {
  185.     // Customisation options
  186.     //
  187.     // Name of the command for this option box (think of it as the base class)
  188.     string $commandName = "snapKey";
  189.     // Title for the option box window
  190.     string $optionBoxTitle;
  191.     string $applyTitle;
  192.  
  193.     $optionBoxTitle = "Snap Keys Options";
  194.     $applyTitle = "Snap keys";
  195.  
  196.     // Build the option box "methods"
  197.     //
  198.     string $callback = ($commandName + "Callback");
  199.     string $setup = ($commandName + "Setup");
  200.  
  201.     // Build the window, with a tab layout
  202.     //
  203.     string $widgetList[] = `getStandardWindow $optionBoxTitle 0 "noOptions"`;
  204.     setUITemplate -pushTemplate DefaultTemplate;
  205.  
  206.     // Make the form invisible while we create the widgets in the window
  207.     //
  208.     formLayout -e -vis false $widgetList[1];
  209.  
  210.     // Attach the widgets.  No tab layout needed.
  211.     //
  212.     snapKeyWidgets $widgetList[2] $selectionConnection $fromGraphEditor;
  213.  
  214.     // Attach the standard buttons
  215.     //
  216.     string $buttonList[] = `addStandardButtons $commandName $applyTitle 
  217.         $widgetList[1] $widgetList[2] "noOptions"`;
  218.  
  219.     // attach commands to the standard buttons
  220.     //
  221.     // Save
  222.     //
  223.     button -e -c ($callback + " " + $widgetList[0] + " false \"\" " +
  224.                   $performAction + " " + $fromGraphEditor 
  225.                   + "; hideOptionBox()") $buttonList[3];
  226.  
  227.     // Close
  228.     //
  229.     button -edit -command hideOptionBox $buttonList[2];
  230.  
  231.     // Reset
  232.     //
  233.     button -edit -command ($setup + " " + $widgetList[0] + " " + $selectionConnection + " true") $buttonList[1];
  234.  
  235.     // DoIt
  236.     //
  237.     button -edit -command ($callback + " " + $widgetList[0] + " true \"" + 
  238.                            $selectionConnection + "\" " + 
  239.                            $performAction + " " + $fromGraphEditor) 
  240.         $buttonList[0];
  241.  
  242.     // Make the form layout visible so we can see what we built, and
  243.     // reset the template
  244.     //
  245.     formLayout -e -vis true $widgetList[1];
  246.     setUITemplate -popTemplate;
  247.  
  248.     //    Customize the 'Help' menu item text.
  249.     //    This is called from 3 different places so look at the selection
  250.     //    connection to try to figure out which one.
  251.     //
  252.     if (match ("graphEditor", $selectionConnection) != "") {
  253.         setOptionBoxHelpTag( "GraphSnap" );
  254.     } else if (match ("dopeSheet", $selectionConnection) != "") {
  255.         setOptionBoxHelpTag( "DopeSnap" );
  256.     } else {
  257.         setOptionBoxHelpTag( "KeysSnapKeys" );
  258.     }
  259.  
  260.     // Call the setup "method" to fill in the current settings
  261.     //
  262.     eval (($setup + " " + $widgetList[0] + " " + $selectionConnection + " false"));    
  263.     showOptionBox();
  264.     showWindow $widgetList[0];
  265.  
  266.     if( $fromGraphEditor ) {
  267.         snapKeyDoSelectionChanged($selectionConnection);    
  268.         scriptJob -protected -event "SelectionChanged" 
  269.             ("snapKeyDoSelectionChanged " + $selectionConnection + "; snapKeyWidgetsEnable " + $selectionConnection + ";")
  270.             -parent $widgetList[2];
  271.     }
  272. }
  273.  
  274.  
  275. proc string assembleCmd( string $selectionConnection, 
  276.                          string $options,
  277.                          string $doSelectNotSnap,
  278.                          int $fromGraphEditor ) 
  279. {
  280.     int $snapTimeValue = `optionVar -q snapKeyTimeValue`;
  281.     int $snapTime = $snapTimeValue != 2;
  282.     int $snapValue = $snapTimeValue != 1;
  283.  
  284.     // doSnapKeyArgList takes a string array
  285.     //
  286.     $cmd = "doSnapKeyArgList 1 { " + 
  287.                 "\"" + `optionVar -q snapKeyAllAnimCurves` + "\"" + 
  288.                 ",\"" + `optionVar -q snapKeyHierarchy` + "\"" + 
  289.                 ",\"" + `optionVar -q snapKeyUseChannelBox` + "\"" + 
  290.                 ",\"" + `optionVar -q snapKeyDriven` + "\"" + 
  291.                 ",\"" + `optionVar -q snapKeyControlPoints` + "\"" + 
  292.                 ",\"" + `optionVar -q snapKeyShapes` + "\"" + 
  293.                 ",\"" + `optionVar -q snapKeyWhichRange` + "\"" + 
  294.                 ",\"" + `optionVar -q snapKeyRange` + "\"" + 
  295.                 ",\"" + $snapTime + "\"" + 
  296.                 ",\"" + $snapValue + "\"" + 
  297.                 ",\"" + `optionVar -q snapKeyTimeMultiple` + "\"" + 
  298.                 ",\"" + `optionVar -q snapKeyValueMultiple` + "\"" + 
  299.                 ",\"" + $doSelectNotSnap + "\"" +
  300.                 ",\"" + $selectionConnection + "\"" + 
  301.                 ",\"" + $options + "\"" +
  302.                 ",\"" + $fromGraphEditor + "\"" +
  303.             " };";
  304.  
  305.     return $cmd;
  306. }
  307.  
  308. //     $version == 1
  309. //    [0] $action                 0 - do the command
  310. //                                 1 - show the option box
  311. //                                2 - return the drag command
  312. //                                3 - do the command (bufferCurve vers.)
  313. //                                4 - show the option box (bufferCurve vers.)
  314. //                                5 - return the drag command (bufferCurve vers.)
  315. //                                6 - do the "selectKey -unsnappedKeys" command 
  316. //                                    associated with the snapKey option settings
  317. //                                7 - return the "selectKey -unsnappedKeys" cmd
  318. //                                    associated with the snapKey option 
  319. //                                    settings    
  320. //    [1] $selectionConnection     name of selection connection to use
  321. //    [2] $fromGraphEditor        true if called from GraphEditor/DopeSheet
  322. //
  323. global proc string performSnapKeyArgList( int $version, string $args[] )
  324. {
  325.     int     $action = $args[0];
  326.     string    $selectionConnection = $args[1];
  327.     int        $fromGraphEditor = $args[2];
  328.  
  329.     string $cmd = "";
  330.  
  331.     switch( $action ) {
  332.         // Snap Key From Edit->Keys menu
  333.         //
  334.         case 0:
  335.             setOptionVars( false );
  336.             $cmd = assembleCmd ($selectionConnection, "noOptions", 0, 
  337.                                 $fromGraphEditor);
  338.             eval( $cmd );
  339.             break;
  340.         case 1:
  341.             snapKeyOptions( $selectionConnection, 0, $fromGraphEditor );
  342.             break;
  343.         case 2:
  344.             setOptionVars( false );
  345.             $cmd = assembleCmd ($selectionConnection, "noOptions", 0, 
  346.                                 $fromGraphEditor);
  347.             break;
  348.         // Snap Key From GE/DS Edit menu
  349.         //
  350.         case 3:
  351.             setOptionVars( false );
  352.             $cmd = assembleCmd ($selectionConnection, "bufferCurve", 0, 
  353.                                 $fromGraphEditor);
  354.             eval( $cmd );
  355.             break;
  356.         case 4:
  357.             snapKeyOptions( $selectionConnection, 3, $fromGraphEditor );
  358.             break;
  359.         case 5:
  360.             setOptionVars( false );
  361.             $cmd = assembleCmd ($selectionConnection, "bufferCurve", 0, 
  362.                                 $fromGraphEditor);
  363.             break;
  364.         // Select Unsnapped from GE/DS menu uses the optionVars
  365.         // from snapKey.
  366.         //
  367.         case 6:
  368.             setOptionVars( false );
  369.             $cmd = assembleCmd ($selectionConnection, "bufferCurve", 1, 
  370.                                 $fromGraphEditor);
  371.             eval( $cmd );
  372.             break;
  373.         case 7:
  374.             setOptionVars( false );
  375.             $cmd = assembleCmd ($selectionConnection, "bufferCurve", 1, 
  376.                                 $fromGraphEditor);
  377.             break;
  378.     }
  379.  
  380.     return ($cmd);
  381. }
  382.